********************************************************************************
** Nondurables, Robust
********************************************************************************
clear
clear matrix
set more off
set scheme s1color
estimates clear
graph drop _all
set matsize 2500
log close _all

*Set Directory
cd "../Do"

********************************************************************************
** PADD DATA
********************************************************************************

import excel "../Data/padd1a.xls", sheet("Data 1") cellrange(A3:B315) firstrow clear
tempfile padd1a_dta
save `padd1a_dta'

import excel "../Data/padd1b.xls", sheet("Data 1") cellrange(A3:B315) firstrow clear
tempfile padd1b_dta
save `padd1b_dta'

import excel "../Data/padd1c.xls", sheet("Data 1") cellrange(A3:B315) firstrow clear
tempfile padd1c_dta
save `padd1c_dta'

import excel "../Data/padd2.xls", sheet("Data 1") cellrange(A3:B326) firstrow clear
tempfile padd2_dta
save `padd2_dta'

import excel "../Data/padd3.xls", sheet("Data 1") cellrange(A3:B326) firstrow clear
tempfile padd3_dta
save `padd3_dta'

import excel "../Data/padd4.xls", sheet("Data 1") cellrange(A3:B326) firstrow clear
tempfile padd4_dta
save `padd4_dta'

import excel "../Data/padd5.xls", sheet("Data 1") cellrange(A3:B326) firstrow clear
tempfile padd5_dta
save `padd5_dta'

use `padd1a_dta', clear 
merge 1:1 Date using `padd1b_dta', nogen
merge 1:1 Date using `padd1c_dta', nogen
merge 1:1 Date using `padd2_dta', nogen
merge 1:1 Date using `padd3_dta', nogen
merge 1:1 Date using `padd4_dta', nogen
merge 1:1 Date using `padd5_dta', nogen

ren NewEnglandPADD1ARegularAl padd_1a
ren CentralAtlanticPADD1BRegul padd_1b
ren LowerAtlanticPADD1CRegular padd_1c
ren MidwestRegularAllFormulations padd_2
ren GulfCoastRegularAllFormulati padd_3
ren RockyMountainRegularAllFormu padd_4
ren WestCoastRegularAllFormulati padd_5
ren Date date

reshape long padd_, i(date) j(padd_region) string 


gen month = month(date)
gen year = year(date)
gen yearm = ym(year, month)
format yearm %tm
drop date year month

ren padd_ gasprice
gen id = 1 if padd_region=="1a"
replace id = 2 if padd_region=="1b"
replace id = 3 if padd_region=="1c"
replace id = 4 if padd_region=="2"
replace id = 5 if padd_region=="3"
replace id = 6 if padd_region=="4"
replace id = 7 if padd_region=="5" 
xtset id yearm

replace gasprice = gasprice*10 // Change to dimes
gen L1_gasprice = L1.gasprice
gen gasprice_infl=((gasprice-L1.gasprice)/L1.gasprice)*100

tempfile padd
save `padd'

********************************************************************************
** LOAD AND CLEAN DATA
********************************************************************************

use ../Data/matched_data_nondurables_jun2018_baseline.dta, clear

*list of spending categories that will add up to nondurables (first version excludes only sports, which is excluded because it has durable goods in it)
#delimit ;
local spendcats "
electricity water heatingfuel phonecable housecleaningproducts housecleaningservice
gardenproducts gardenservice clothing personalcare drugs healthcareservices medsupplies entertainment
hobbies personalservices otherchildspending foodhome foodout gasoline";
#delimit cr

*based on content of "spendcats" above, nondurables defined as all included in that group except sports
egen nondurables = rowtotal(`spendcats')

*not that nondurables has one outlier value over 29000 (for monthly spending on nondurable goods/services) 
*before running some regressions, extreme values for nondurables will be omitted; a small number of zeroes will be dropped

drop ethnicity

recode mort (5=0)
recode stocks (5=0)
recode retacct (5=0)
recode howner (5=0)

* Recode some expectations variables from the Inflation surveys. 

* unemployment dummies
recode q6 (1=1) (2 3 = 0), gen(unemp_increase)
recode q6 (3=1) (1 2 = 0), gen(unemp_decrease)

gen conditions_12m = q2a
* note everybody who says "other" is in separate category
recode q2a (1=1) (2 3 = 0), gen(conditions_12m_better)
recode q2a (2=1) (1 3 = 0), gen(conditions_12m_worse)

gen interestrate_12m = q7
recode interestrate_12m (1=1) (2 3 = 0), gen(intrate_12m_up)
recode interestrate_12m (3=1) (1 2 = 0), gen(intrate_12m_down)

gen bconditions_12m = q4
* note everybody who says "other" is in separate category
recode q4 (1=1) (2 3 = 0), gen(bconditions_12m_better)
recode q4 (2=1) (1 3 = 0), gen(bconditions_12m_worse)

* house price forecasts
gen hppoint = .
replace hppoint = 0 if q41==3
replace hppoint = q42 if q41==1
replace hppoint = -q42 if q41==2
* there are some extreme outliers (in the tens of thousands)
replace hppoint = . if abs(hppoint)>=200
la var hppoint "House price expectation"

* Deflation: using 2012q1 PCUN (nondurables CPI): generate a new variable so regressions can be run on nominal and real data alternatively
* from Arman: note that PCUN was redefined in the haver do file to give 2012q1 dollars

rename spend_month date_monthly
sort date_monthly
merge m:1 date_monthly using "../Data/haver_m.dta"

tab _merge
drop if _merge==2
drop _merge

*MB: my simple deflation command: just deflating my main measure of nondurables
gen nondurables_real=nondurables/PCUN
rename date_monthly spend_month
*note real values are only a little higher on average than nominal values

*** Prepare some additional descriptives
* Race isn't reported in all periods. 
preserve
collapse (mean) race , by(prim_key)
sort prim_key
tempfile race
save `race'
restore

drop race
sort prim_key
merge m:1 prim_key using `race'
tab _merge
drop _merge
drop if prim_key==""

recode race (1=1) (nonmissing = 0), gen(white)
gen nonwhite = 1-white
recode gender (2=1) (1=0), gen(female)
recode highesteducation (4 9 = 0) (10/16 = 1), gen(coll)

* q31s* gives codes. Kind of odd that they've created separate variables. 
*MB: odd to generate employed variable, because everyone in sample is employed--however some also say they are retired (?) 
gen employed = . 
replace employed=1 if q31s1==1
replace employed = 0 if (q31s2==2 | q31s3==3 | q31s4==4 | q31s5==5 | q31s6==6 | q31s7==7) & q31s1!=1


* generate currently retired variable.
*odd that some are retired even though all are employed; how do retired people have wage growth expectations? they may be working a small job anyway
drop retired 
gen retired = . 
replace retired = 1 if q31s5==5
replace retired = 0 if (q31s1==1 | q31s2==2 | q31s3==3 | q31s4==4 | q31s6==6 | q31s7==7) & q31s5!=5
tab retired

*more preparation for regressions
local expectations "intrate_12m_up intrate_12m_down unemp_increase unemp_decrease rw_expect d_wageiqr hppoint"
local infl1 "d_inflmedian d_infliqr"
local infl2 "d_longinflmedian d_longinfliqr"

*MBwhen using lagss--may need to rename lagged vars or these locals to match
*local lags1 "lagE_d_inflmedian lagE_d_infliqr" ;
*local lags2 "lagE_d_longinflmedian lagE_d_longinfliqr" ;

local spec1 "Short-Run Infl. Exp."
local spec2 "Medium-Run Infl. Exp."
la var d_inflmedian "Inflation Expectations"
la var d_infliqr "Inflation Uncertainty"

*replace howner=0 if howner==.
*adds ten people to homeowner status; there are still some with howner_fix==0 who have positive mortgage payment, but missing data for has mortgage and/or mortgage amount
*two observations have howner==0 and mort==1 (say they're not a homeowner but they say they have a mortgage); not important so not recoding them for now

*the mortgage dummy is non-missing for over 2000 observations; however the mortgage balance (amtmort) is observed only for 990 people
*tab mort
*reasonable recode of mortgage dummy based on other information
replace mort = 0 if (howner!=1 | mortgage==0) & mort==.
replace mort = 1 if (howner==1 | (mortgage>0 & mortgage!=.)) & mort==.
la var mort "Mortgage Indicator"

*MB: generating quasi-continuous income variable based on midpoint of ranges of annual household income variables (familyincome and familyincome_part2)
rename familyincome inc2
rename familyincome_part2 inc2_2
drop if inc2==.
*here is the income variable: "new_faminc"
gen new_faminc=.
replace new_faminc=2500 if inc2==1
replace new_faminc=6250 if inc2==2
replace new_faminc=8750 if inc2==3
replace new_faminc=11250 if inc2==4
replace new_faminc=13750 if inc2==5
replace new_faminc=17500 if inc2==6
replace new_faminc=22500 if inc2==7
replace new_faminc=27500 if inc2==8
replace new_faminc=32500 if inc2==9
replace new_faminc=37500 if inc2==10
replace new_faminc=45000 if inc2==11
replace new_faminc=55000 if inc2==12
replace new_faminc=67500 if inc2==13
replace new_faminc=87500 if inc2==14 & (inc2_2==1 | inc2_2==.)
*above accounts for one person with inc2==14 and inc2_2 missing; not sure why that's the case but I asigned them the lowest category of income over $75000
replace new_faminc=112500 if inc2==14 & inc2_2==2
replace new_faminc=162500 if inc2==14 & inc2_2==3
replace new_faminc=237500 if inc2==14 & inc2_2==4

gen log_new_faminc=log(new_faminc)


sort prim_key spend_month
*bringing in SAMPLE WEIGHTS, to monthly data: warning, we might lose observations if the set requiring weights has changed ; this will affect our ability to run regs using non-employed types (can only do unweighted) 
merge m:1 prim_key using ../Data/mweights_pooled
*these are the reg weights, the full sample weights will still be called weight_full
*weight variable is called "weight_samp" to indicate the weights were designed for the regression sample
*195 observations dropped that didn't merge with a weight_samp
drop if _merge!=3
drop _merge

*define regression sample before recentering any variables
*drop people with extreme values for spending, inflation expectations, mortgage payment that looks like a mortgage balance
*outliers identified by Ali: turn on as alternative MB: the below prim_key doesn't look suspicious to me---this drop may have been related to the previous (bad) income variable
*drop if prim_key=="5041140:1"
*drops 
drop if mortgage>200000 & mortgage!=.
*drops 17 observations
drop if d_inflmedian>35
*drops 13 observationsZ
drop if nondurables==0
*drops 1 observation
drop if nondurables>28000

*assigning locals for weights (can turn on or off in regression)
local weights "[pweight=weight_samp]"
local weights_full "[pweight=weight_full]"
local pwfile "_pw"
*drop those with missing values for regressors
la var d_inflmedian "Inflation Expectation"
la var d_infliqr "Inflation Uncertainty"
la var d_longinflmedian "Inflation Expectation (MR)"
la var d_longinfliqr "Inflation Uncertainty (MR)"
la var lag_IE "Lagged Inflation Expectation"
la var lag_infl_iqr "Lagged Inflation Uncertainty"

*variable for sum of monthly payments--interactions between this variable and IE may be included in some models
gen payments=mortgage+car if howner==1
replace payments=rent+car if howner!=1
gen log_payments=.
replace log_payments=log(payments) if payments>0
replace log_payments=0 if payments==0
la var log_payments "Monthly Payments (Log)"
*drop one observation with extreme value for payments (110,000): only if running a regression interacting with payments
drop if payments>100000


*defining sample; removing those with missing values
drop if weight_samp==.
drop if d_inflmedian==.
drop if d_infliqr==.
drop if nondurables==.
*dropping lagged IE: only need if we include lag IE in regression 
drop if lag_IE==.
drop if lag_infl_iqr==.
*new income variable: new_faminc is recode of categorical variables familyincome and familyincome_part2; former variable was earnings last month and highly unreliable
drop if new_faminc==.
drop if intrate_12m_up==.
drop if intrate_12m_down==.
drop if unemp_increase==.
drop if unemp_decrease==.
drop if rw_expect==.
drop if d_wageiqr==.
drop if rage==.
drop if nonwhite==.
drop if female==.
drop if coll==.
drop if retired==.
drop if mort==.
*alternative: comment out the last two drops and omit howner and hppoint from regressions 
*below results in loss of 300+ observations--will retain alternative and omit hppoint from the regression
drop if hppoint==.
*this drops 111 observations--can run alternative model without howner dummy and include these 
drop if howner==.

*replacing inflation expectations (and lags) with centered version: note that means are not weighted; this doesn't matter because weighted mean is within 0.04 ppts of unweighted mean IE
egen IE_sampmean=mean(d_inflmedian) 
replace d_inflmedian=d_inflmedian-IE_sampmean
egen lag_IE_sampmean=mean(lag_IE)
replace lag_IE=lag_IE-lag_IE_sampmean
egen lag_unc_sampmean=mean(lag_infl_iqr)
replace lag_infl_iqr=lag_infl_iqr-lag_unc_sampmean

*replacing log monthly payments with centered version
egen log_payments_sampmean=mean(log_payments)
replace log_payments=log_payments-log_payments_sampmean
*replacing log household income with centered version
egen log_inc_sampmean=mean(log_new_faminc)
replace log_new_faminc=log_new_faminc-log_inc_sampmean

sort prim_key spend_month

*need to xtset the data
destring prim_key, generate(id_new) ignore(":")
xtset id_new spend_month

*generate within-person means of time-varying independent variables: note that for variables that were recentered above, these now represent the within-household average of the deviation from the sample mean for the given variable
egen IE_bar=mean(d_inflmedian), by(id_new)
egen IE_unc_bar=mean(d_infliqr), by(id_new)
egen IE_bar2=mean(d_longinflmedian), by(id_new)
egen mr_IE_unc_bar=mean(d_longinfliqr), by(id_new)
egen new_faminc_bar=mean(new_faminc), by(id_new)
egen log_new_faminc_bar=mean(log_new_faminc), by(id_new)
egen intrate_up_bar=mean(intrate_12m_up), by(id_new)
egen intrate_down_bar=mean(intrate_12m_down), by(id_new)
egen unemp_up_bar=mean(unemp_increase), by(id_new)
egen unemp_down_bar=mean(unemp_decrease), by(id_new)
egen rw_bar=mean(rw_expect), by(id_new)
egen rw_unc_bar=mean(d_wageiqr), by(id_new)
egen hp_bar=mean(hppoint), by(id_new)
egen howner_bar=mean(howner), by(id_new)
egen mort_bar=mean(mort), by(id_new)
egen log_payments_bar=mean(log_payments), by(id_new)
** Within-person mean of lagged IE and lagged infl uncertainty (new)
egen lag_IE_bar=mean(lag_IE), by(id_new)
egen lag_IE_unc_bar=mean(lag_infl_iqr), by(id_new)


** Adjusting vars for labelling problems (?) Something weird going on..
gen mort2 = mort
la var mort2 "Has Mortgage"
gen howner2 = howner
la var howner2 "Homeowner"
drop mort howner
ren mort2 mort
ren howner2 howner

** Reverse College
gen nocoll = 1-coll

** Reverse Mortgage
gen nomort = 1-mort
gen nomort_bar = 1-mort_bar

********************************************************************************
** REGRESSIONS
********************************************************************************

** Label variables for tables
la var log_new_faminc "Household Income (Log)"
la var log_payments "Monthly Payments (Log)"
la var intrate_12m_up "Int Rates Inc"
la var intrate_12m_down "Int Rates Dec"
la var rw_expect "Real Wage Expectation"
la var d_wageiqr "Wage Uncertainty"
la var nomort "No Mortgage"
la var rage "Age" 
la var nonwhite "Non-White"
la var female "Female"
la var retired "Retired"
la var howner "Homeowner"
la var hppoint "House Price Expectation"
la var unemp_increase "Unemp Inc"
la var unemp_decrease "Unemp Dec"

la var IE_bar "Mean Inflation Expectation"
la var IE_unc_bar "Mean Inflation Uncertainty"
la var log_new_faminc_bar "Mean Log Household Income"
la var log_payments_bar "Mean Log Monthly Payments"
la var intrate_up_bar "Mean Expects Interest Rate Increase" 
la var intrate_down_bar "Mean Expects Interest Rate Decrease"
la var rw_bar "Mean Real Wage Expectation"
la var rw_unc_bar "Mean Wage Uncertainty"
la var nomort_bar "Mean No Mortgage Indicator"
la var howner_bar "Mean Homeowner"
la var hp_bar "Mean House Price Expectation"
la var unemp_up_bar "Mean Expects Unemployment Increase"
la var unemp_down_bar "Mean Expects Unemployment Decrease"

la var nocoll "No College"

la var IE_bar2 "Mean Inflation Expectation (MR, within-subject)" 
la var mr_IE_unc_bar "Mean Inflation Uncertainty (MR, within-subject)"

*generating regression samples
*generate variable that equals 1 in all cases, to sum to determine observations per person
gen pre_obs=1
*generate sum of observations per person
egen obs=total(pre_obs), by(id_new)
*define sample  based on sufficient observation
gen nondurables_sample_hp=(obs>=3)

count if nondurables_sample_hp==1

#delimit ;
eststo x0: xtgee nondurables_real d_inflmedian d_infliqr
log_new_faminc log_payments 
i.intrate_12m_up i.intrate_12m_down  
rw_expect d_wageiqr 
i.nomort rage i.nonwhite i.female i.retired 
i.howner hppoint
i.unemp_increase i.unemp_decrease 
IE_bar IE_unc_bar 
log_new_faminc_bar log_payments_bar
intrate_up_bar intrate_down_bar 
rw_bar rw_unc_bar nomort_bar 
howner_bar hp_bar 
unemp_up_bar unemp_down_bar   
c.d_inflmedian##i.nocoll c.d_infliqr##i.nocoll
c.d_inflmedian##c.log_new_faminc_bar c.d_inflmedian##c.log_payments_bar c.d_inflmedian##c.nomort_bar  
i.spend_month [pweight=weight_samp] if nondurables_sample_hp==1, 
family(poisson) link(log) corr(exch) vce(robust);
#delimit cr
estadd local cre "Yes"

** a.	Gas Price Inflation Variable
preserve

local padd1a_s "21 7 39" //no maine and vermont
local padd1b_s "32 30 38 20 51" //no de incl. DC
local padd1c_s "48 46 33 40 10 9"
local padd2_s "34 27 16 36 23 15 25 49 13 22 14 35 17 42" //no sd
local padd3_s "43 4 18 24" //no nm al
local padd4_s "26 12 44 6" //no wy
local padd5_s "47 37 28 5 3"

foreach region in padd1a padd1b padd1c padd2 padd3 padd4 padd5{
	gen `region' = .
	foreach ii in ``region'_s' { //21 7 39 {
		replace `region' = 1 if statereside==`ii'
	}
}
gen padd_region = ""
foreach vv in 1a 1b 1c 2 3 4 5{
	replace padd_region = "`vv'" if padd`vv'==1
}
gen yearm = exp_month
merge m:1 yearm padd_region using `padd'
drop if _merge==2
drop _merge

la var gasprice "PADD Gas Price"
la var L1_gasprice "Lagged PADD Gas Price"
la var gasprice_infl "Regional Gas Price Inflation"

encode padd_region, gen(padd_region2)
la var padd_region2 "PADD Region"


#delimit ;
eststo x1: xtgee nondurables_real c.d_inflmedian##i.nocoll c.d_infliqr##i.nocoll log_payments 
gasprice_infl i.padd_region2
c.d_inflmedian##c.log_payments_bar c.d_inflmedian##c.nomort_bar c.d_inflmedian##c.log_new_faminc_bar 
i.unemp_increase i.unemp_decrease i.intrate_12m_up i.intrate_12m_down  
rw_expect d_wageiqr  log_new_faminc  i.nomort i.nocoll rage i.nonwhite i.female i.retired i.howner hppoint
IE_bar IE_unc_bar intrate_up_bar intrate_down_bar 
unemp_up_bar unemp_down_bar rw_bar rw_unc_bar howner_bar hp_bar 
i.spend_month [pweight=weight_samp] if nondurables_sample_hp==1, 
family(poisson) link(log) corr(exch) vce(robust);
#delimit cr
estadd local cre "Yes"

restore

** b.	Lagged Expectations   

#delimit ;
eststo x2: xtgee nondurables_real c.d_inflmedian##i.nocoll c.d_infliqr##i.nocoll log_payments 
c.d_inflmedian##c.log_payments_bar c.d_inflmedian##c.nomort_bar c.d_inflmedian##c.log_new_faminc_bar 
i.unemp_increase i.unemp_decrease i.intrate_12m_up i.intrate_12m_down  
rw_expect d_wageiqr  log_new_faminc  i.nomort i.nocoll rage i.nonwhite i.female i.retired i.howner hppoint
IE_bar IE_unc_bar intrate_up_bar intrate_down_bar 
unemp_up_bar unemp_down_bar rw_bar rw_unc_bar howner_bar hp_bar
c.lag_IE##i.nocoll c.lag_infl_iqr##i.nocoll 
i.spend_month [pweight=weight_samp] if nondurables_sample_hp==1, 
family(poisson) link(log) corr(exch) vce(robust);
#delimit cr
estadd local cre "Yes"

margins, eydx(d_inflmedian) at(nocoll = 1)
margins, eydx(d_inflmedian) at(nocoll = 0)
margins, eydx(lag_IE) at(nocoll = 1)
margins, eydx(lag_IE) at(nocoll = 0)

** c.	Medium-run expectations 

#delimit ;
eststo x3: xtgee nondurables_real c.d_inflmedian##i.nocoll c.d_infliqr##i.nocoll log_payments 
c.d_inflmedian##c.log_payments_bar c.d_inflmedian##c.nomort_bar c.d_inflmedian##c.log_new_faminc_bar 
i.unemp_increase i.unemp_decrease i.intrate_12m_up i.intrate_12m_down  
rw_expect d_wageiqr  log_new_faminc  i.nomort i.nocoll rage i.nonwhite i.female i.retired i.howner hppoint
IE_bar IE_unc_bar intrate_up_bar intrate_down_bar 
unemp_up_bar unemp_down_bar rw_bar rw_unc_bar howner_bar hp_bar 
c.d_longinflmedian##i.nocoll c.d_longinfliqr##i.nocoll IE_bar2 mr_IE_unc_bar
i.spend_month [pweight=weight_samp] if nondurables_sample_hp==1, 
family(poisson) link(log) corr(exch) vce(robust);
#delimit cr
estadd local cre "Yes"

** d. Unemployment expectations interacted with college status

#delimit ;
eststo x4: xtgee nondurables_real c.d_inflmedian##i.nocoll c.d_infliqr##i.nocoll log_payments 
c.d_inflmedian##c.log_payments_bar c.d_inflmedian##c.nomort_bar c.d_inflmedian##c.log_new_faminc_bar 
i.nocoll##i.unemp_increase i.nocoll##i.unemp_decrease i.intrate_12m_up i.intrate_12m_down  
rw_expect d_wageiqr  log_new_faminc  i.nomort i.nocoll rage i.nonwhite i.female i.retired i.howner hppoint
IE_bar IE_unc_bar intrate_up_bar intrate_down_bar 
unemp_up_bar unemp_down_bar rw_bar rw_unc_bar howner_bar hp_bar 
i.spend_month [pweight=weight_samp] if nondurables_sample_hp==1, 
family(poisson) link(log) corr(exch) vce(robust);
#delimit cr
estadd local cre "Yes"

** e. Overlapping sample of 163 respondents
preserve

merge m:1 id_new using "../Data/overlap_sample_ids.dta", keep(3) 

#delimit ;
eststo x5: xtgee nondurables_real c.d_inflmedian##i.nocoll c.d_infliqr##i.nocoll log_payments 
c.d_inflmedian##c.log_payments_bar c.d_inflmedian##c.nomort_bar c.d_inflmedian##c.log_new_faminc_bar 
i.unemp_increase i.unemp_decrease i.intrate_12m_up i.intrate_12m_down  
rw_expect d_wageiqr  log_new_faminc  i.nomort i.nocoll rage i.nonwhite i.female i.retired i.howner hppoint
IE_bar IE_unc_bar intrate_up_bar intrate_down_bar 
unemp_up_bar unemp_down_bar rw_bar rw_unc_bar howner_bar hp_bar 
i.spend_month [pweight=weight_samp] if nondurables_sample_hp==1, 
family(poisson) link(log) corr(exch) vce(robust);
#delimit cr
estadd local cre "Yes"

restore

** f. Balanced sample (those with more than 7 observations)
preserve 

*------------------------------------------------------------------------------*
** Restrict on having nonzero durables spending in at least one period (based on total durables spending within household) 
** Define sample  based on sufficient observation
replace nondurables_sample_hp=(obs>=7)
*------------------------------------------------------------------------------*

#delimit ;
eststo x6: xtgee nondurables_real c.d_inflmedian##i.nocoll c.d_infliqr##i.nocoll log_payments 
c.d_inflmedian##c.log_payments_bar c.d_inflmedian##c.nomort_bar c.d_inflmedian##c.log_new_faminc_bar 
i.unemp_increase i.unemp_decrease i.intrate_12m_up i.intrate_12m_down  
rw_expect d_wageiqr  log_new_faminc  i.nomort i.nocoll rage i.nonwhite i.female i.retired i.howner hppoint
IE_bar IE_unc_bar intrate_up_bar intrate_down_bar 
unemp_up_bar unemp_down_bar rw_bar rw_unc_bar howner_bar hp_bar 
i.spend_month [pweight=weight_samp] if nondurables_sample_hp==1, 
family(poisson) link(log) corr(exch) vce(robust);
#delimit cr
estadd local cre "Yes"

restore

** g. Sample excluding outlier inflation months

preserve 

drop if exp_month == tm(2010m6)
drop if exp_month == tm(2011m3)
drop if exp_month == tm(2011m9)
drop if exp_month == tm(2012m2)

#delimit ;
eststo x7: xtgee nondurables_real c.d_inflmedian##i.nocoll c.d_infliqr##i.nocoll log_payments 
c.d_inflmedian##c.log_payments_bar c.d_inflmedian##c.nomort_bar c.d_inflmedian##c.log_new_faminc_bar 
i.unemp_increase i.unemp_decrease i.intrate_12m_up i.intrate_12m_down  
rw_expect d_wageiqr  log_new_faminc  i.nomort i.nocoll rage i.nonwhite i.female i.retired i.howner hppoint
IE_bar IE_unc_bar intrate_up_bar intrate_down_bar 
unemp_up_bar unemp_down_bar rw_bar rw_unc_bar howner_bar hp_bar 
i.spend_month [pweight=weight_samp] if nondurables_sample_hp==1, 
family(poisson) link(log) corr(exch) vce(robust);
#delimit cr
estadd local cre "Yes"

restore

** h. Sample excluding 2012 (due to CES comparison)

preserve
drop if yofd(dofq(quarter)) == 2012

#delimit ;
eststo x8: xtgee nondurables_real c.d_inflmedian##i.nocoll c.d_infliqr##i.nocoll log_payments 
c.d_inflmedian##c.log_payments_bar c.d_inflmedian##c.nomort_bar c.d_inflmedian##c.log_new_faminc_bar 
i.unemp_increase i.unemp_decrease i.intrate_12m_up i.intrate_12m_down  
rw_expect d_wageiqr  log_new_faminc  i.nomort i.nocoll rage i.nonwhite i.female i.retired i.howner hppoint
IE_bar IE_unc_bar intrate_up_bar intrate_down_bar 
unemp_up_bar unemp_down_bar rw_bar rw_unc_bar howner_bar hp_bar 
i.spend_month [pweight=weight_samp] if nondurables_sample_hp==1, 
family(poisson) link(log) corr(exch) vce(robust);
#delimit cr
estadd local cre "Yes"

restore

/*
** i.	Lagged Expectations, balanced panel

*------------------------------------------------------------------------------*
** Restrict on having nonzero durables spending in at least one period (based on total durables spending within household) 
** Define sample  based on sufficient observation
replace nondurables_sample_hp=(obs>=7)
*------------------------------------------------------------------------------*

#delimit ;
eststo x9: xtgee nondurables_real c.d_inflmedian##i.nocoll c.d_infliqr##i.nocoll log_payments 
c.d_inflmedian##c.log_payments_bar c.d_inflmedian##c.nomort_bar c.d_inflmedian##c.log_new_faminc_bar 
i.unemp_increase i.unemp_decrease i.intrate_12m_up i.intrate_12m_down  
rw_expect d_wageiqr  log_new_faminc  i.nomort i.nocoll rage i.nonwhite i.female i.retired i.howner hppoint
IE_bar IE_unc_bar intrate_up_bar intrate_down_bar 
unemp_up_bar unemp_down_bar rw_bar rw_unc_bar howner_bar hp_bar
c.lag_IE##i.nocoll c.lag_infl_iqr##i.nocoll 
i.spend_month [pweight=weight_samp] if nondurables_sample_hp==1, 
family(poisson) link(log) corr(exch) vce(robust);
#delimit cr
estadd local cre "Yes"
*/
 
** Export Tables - Baseline
esttab x0 x1 x2 x4 x5 x6 x7 x8 using "../Tables/reg_tabs_nondurables_robust.tex", replace ///
label style(tex) star(* 0.10 ** 0.05 *** 0.01) b(%5.3f) se(%5.3f) booktabs longtable ///
stats(cre chi2 p N, labels("Correlated Random Effects" "Chi$^2$" "P Value" "Sample Size") fmt(%5s %5.2fc %5.2fc %7.0g )) varwidth(45) varlabels(_cons Constant gasprice_infl "Regional Gas Price Inflation") ///
title("Table A9: Real Nondurable Goods Spending vs. Year-Ahead Expectations, Baseline Sample, GEE estimation") ///
/*indicate("Correlated Random Effects = IE_unc_bar") drop(_cons rage 1.nonwhite 1.female 1.retired *spend_month* log_payments log_payments_bar unemp_up_bar unemp_down_bar intrate_up_bar intrate_down_bar rw_bar hp_bar howner_bar nomort_bar hppoint 2.padd_region2 3.padd_region2 4.padd_region2 5.padd_region2 6.padd_region2 7.padd_region2) */ ///
drop(*spend_month* log_payments 1.intrate_12m_up 1.intrate_12m_down rw_expect d_wageiqr 1.nomort rage 1.nonwhite 1.female 1.retired 1.howner hppoint IE_unc_bar log_payments_bar intrate_up_bar intrate_down_bar rw_bar rw_unc_bar nomort_bar howner_bar hp_bar 2.padd_region2 3.padd_region2 4.padd_region2 5.padd_region2 6.padd_region2 7.padd_region2 c.d_inflmedian#c.log_payments_bar c.d_inflmedian#c.nomort_bar _cons) ///
numbers msign(--) eqlabels(none) ///
nomtitles nonotes nobaselevels noomitted ///
substitute( ///
"\bottomrule" "\bottomrule `=char(13)'\caption*{\normalsize \doublespacing Standard errors in parentheses. \\ `=char(13)'\textit{Note:} Each column includes time fixed effects. All means refer to within-subject means. Model (1) is unaltered. Model (2) includes gas price inflation and regional controls. Model (3) includes the lagged inflation expectation and lagged inflation uncertainty and their interactions with the no college indicator. Model (4) includes the interactions of the unemployment expectations indicators with the no college indicator. Model (5) restricts to the overlap sample between the durables and nondurables samples. Model (6) restricts to households in the nondurables sample with more than 7 observations. Model (7) excludes months with outlier median inflation expectations: June 2010, March 2011, September 2011, February 2012. Model (8) excludes observations from 2012, in which the nondurable sample's spending patterns were most different from the CES. The full set of coefficients is presented in Table A19. Robust standard errors are clustered at the level of the individual respondent. \sym{*} \(p<0.10\), \sym{**} \(p<0.05\), \sym{***} \(p<0.01\) }" ///
"No College=1" "No College" ///
"Unemp Inc=1" "Expects Unemployment Increase" ///
"Unemp Dec=1" "Expects Unemployment Decrease" ///
"Int Rates Inc=1" "Expects Interest Rate Increase" ///
"Int Rates Dec=1" "Expects Interest Rate Decrease" ///
"No Mortgage=1" "No Mortgage Indicator" ///
"Non-White=1" "Non-White" ///
"Female=1" "Female" ///
"Retired=1" "Retired" ///
"Homeowner=1" "Homeowner" ///
"Inflation Expectation $\times$ Mean No Mortgage Indicator" "Mean No Mortgage Indicator $\times$ Inflation Expectation" ///
"Inflation Expectation $\times$ Mean Log Monthly Payments" "Mean Log Monthly Payments $\times$ Inflation Expectation" ///
"Inflation Expectation $\times$ Mean Log Household Income" "Mean Log Household Income $\times$ Inflation Expectation" ///
"\caption{" "\caption*{" ///
)

esttab x0 x1 x2 x4 x5 x6 x7 x8 using "../Tables/reg_tabs_nondurables_robust_full.tex", replace ///
label style(tex) star(* 0.10 ** 0.05 *** 0.01) b(%5.3f) se(%5.3f) booktabs longtable ///
stats(cre chi2 p N, labels("Correlated Random Effects" "Chi$^2$" "P Value" "Sample Size") fmt(%5s %5.2fc %5.2fc %7.0g )) varwidth(45) varlabels(_cons Constant gasprice_infl "Regional Gas Price Inflation") ///
title("Table A19: Full Specification for Table A9, Real Nondurable Goods Spending vs. Year-Ahead Expectations, Baseline Sample, GEE estimation") ///
/*indicate("Correlated Random Effects = IE_unc_bar") drop(_cons rage 1.nonwhite 1.female 1.retired *spend_month* log_payments log_payments_bar unemp_up_bar unemp_down_bar intrate_up_bar intrate_down_bar rw_bar hp_bar howner_bar nomort_bar hppoint 2.padd_region2 3.padd_region2 4.padd_region2 5.padd_region2 6.padd_region2 7.padd_region2) */ ///
drop(*spend_month* 2.padd_region2 3.padd_region2 4.padd_region2 5.padd_region2 6.padd_region2 7.padd_region2) ///
numbers msign(--) eqlabels(none) ///
nomtitles nonotes nobaselevels noomitted ///
substitute( ///
"\bottomrule" "\bottomrule `=char(13)'\caption*{\normalsize \doublespacing Standard errors in parentheses. \\ `=char(13)'\textit{Note:} Each column includes time fixed effects. All means refer to within-subject means. Model (1) is unaltered. Model (2) includes gas price inflation and regional controls. Regional controls are omitted. Model (3) includes the lagged inflation expectation and lagged inflation uncertainty and their interactions with the no college indicator. Model (4) includes the interactions of the unemployment expectations indicators with the no college indicator. Model (5) restricts to the overlap sample between the durables and nondurables samples. Model (6) restricts to households in the nondurables sample with more than 7 observations. Model (7) excludes months with outlier median inflation expectations: June 2010, March 2011, September 2011, February 2012. Model (8) excludes observations from 2012, in which the nondurable sample's spending patterns were most different from the CES. Robust standard errors are clustered at the level of the individual respondent. \sym{*} \(p<0.10\), \sym{**} \(p<0.05\), \sym{***} \(p<0.01\) }" ///
"No College=1" "No College" ///
"Unemp Inc=1" "Expects Unemployment Increase" ///
"Unemp Dec=1" "Expects Unemployment Decrease" ///
"Int Rates Inc=1" "Expects Interest Rate Increase" ///
"Int Rates Dec=1" "Expects Interest Rate Decrease" ///
"No Mortgage=1" "No Mortgage Indicator" ///
"Non-White=1" "Non-White" ///
"Female=1" "Female" ///
"Retired=1" "Retired" ///
"Homeowner=1" "Homeowner" ///
"Inflation Expectation $\times$ Mean No Mortgage Indicator" "Mean No Mortgage Indicator $\times$ Inflation Expectation" ///
"Inflation Expectation $\times$ Mean Log Monthly Payments" "Mean Log Monthly Payments $\times$ Inflation Expectation" ///
"Inflation Expectation $\times$ Mean Log Household Income" "Mean Log Household Income $\times$ Inflation Expectation" ///
"\caption{" "\caption*{" ///
)